import { Component, ViewChild, Injector} from '@angular/core';
import { ModalDirective } from 'ngx-bootstrap';
import { AppComponentBase } from '@shared/common/app-component-base';

import { LocationServiceProxy } from '@shared/service-proxies/service-proxies';

@Component({
  selector: 'printLocationLabel',
  templateUrl: './print-location-label.component.html'
})

export class PrintLocationLabelComponent extends AppComponentBase {
  @ViewChild('createOrEditModal') modal: ModalDirective;
  @ViewChild('scanModal') scanModal: ModalDirective;

  active = false;
  saving = false;

  printCSS: string[];
  printStyle: string;
  printBtnBoolean = true;

  id:string;
  locationName :string;

  constructor(
    injector: Injector,
    private _locationService:LocationServiceProxy
  ) {
    super(injector);

    this.printCSS = ['http://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css'];
    this.printStyle =
      `
      th, td {
        color: black !important;
     }
     `;
  }

  printComplete() {
    this.printBtnBoolean = true;
  }
  beforePrint() {
    this.printBtnBoolean = false;
  }

  show(id: number): void {
    this.active = true;
    this._locationService.getPositionsById(id)
    .subscribe(result => {
      console.log(id)
      this.id=String(id);
      this.locationName=result;
      this.modal.show();
    });
    this.modal.show();
  }

  save(): void {
    this.saving = true;
    this.message.confirm('确认要打印吗？', isConfirmed => {
      if (isConfirmed) {

        this.scanModal.show();
      }
    });
  }

  close(): void {
    this.active = false;
    this.modal.hide();
  }
}
